/**
 * Triangle exercises for TW101 Module 1
 *
 * Created by dmorti on 12/02/14.
 */
public class TriangleExercises {
    public static void main(String[] args) {
        TriangleExercises exercises = new TriangleExercises();

        System.out.println("Exercise 1: The Easiest Exercise Ever");
        exercises.exercise1();

        System.out.println("\nExercise 2: Draw a Horizontal Line");
        exercises.exercise2(8);

        System.out.println("\nExercise 3: Draw a Vertical Line");
        exercises.exercise3(3);

        System.out.println("\nExercise 4: Draw a Right-angled Triangle");
        exercises.exercise4(5);
    }

    private void exercise1() {
        System.out.println("*");
    }

    private void exercise2(int n) {
        System.out.println(horizontalLine(n));
    }

    private void exercise3(int n) {
        System.out.println(verticalLine(n));
    }

    private void exercise4(int n) {
        for (int i=0; i<n; i++) {
            System.out.println(horizontalLine(i+1));
        }
    }

    private String horizontalLine(int n) {
        return repeatString(n, "*");
    }

    private String verticalLine(int n) {
        return repeatString(n, "*\n");
    }

    private String repeatString(int n, String s) {
        return new String(new char[n]).replace("\0", s);
    }
}
